import { observable, action, computed } from 'mobx';
import { Browser, ListPage, BrowserHrm, BrowserCity } from 'weaver-mobile-page';

export default class BrowserAllBrowserStore {
  @observable browser = new Browser.Store({ route: '/app/excelTaskView' });
  @observable browserMutil = new Browser.Store({ route: '/app/excelTaskView' });
  @observable dataUrl = '/api/public/browser/data/';
  @observable conditionURL = '/api/public/browser/condition/';
  @observable dataParams = '';
  @observable dataParamsObj = {};
  @observable type = 16;
  @observable tabs = '';
  @observable value = '1';
  @observable browserInstance;
  @observable list = new ListPage.Store();
  // 目前搜索历史存放 localStorage，需要指定固定 id
  @observable browserHrm = new BrowserHrm.Store({ route: '/app/excelTaskView', id: 'singleHrm' });
  // @observable browserHrmValue = [];
  @observable browserHrm1 = new BrowserHrm.Store({ route: '/app/excelTaskView', id: 'mulHrm' });
  @observable browserHrmValue1 = [];
  @observable browserCitygj = new BrowserCity.Store({ route: '/app/excelTaskView' });
  @observable browserCitysf = new BrowserCity.Store({ route: '/app/excelTaskView' });
  @observable browserCitycs = new BrowserCity.Store({ route: '/app/excelTaskView' });
  @observable browserCityqx = new BrowserCity.Store({ route: '/app/excelTaskView' });

  @observable browserValue;
  @observable currentCell;
  @observable currentValue;
  @observable isSingle = true;

  @computed get tabsArr() {
    let arr = [];
    try {
      arr = JSON.parse(this.tabs);
    } catch (e) {
      // console.log('e: ', e);
    }
    return arr;
  }

  // @computed get dataParamsObj() {
  //   // let obj = {};
  //   // try {
  //   //   obj = JSON.parse(this.dataParams);
  //   // } catch (e) {
  //   //    console.log('e: ', e);
  //   // }
  //   // console.log(obj,this.dataParams,"obj")
  //   return this.dataParams;
  // }

  @action
  setState = (params = {}) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
  }

  delHtmlTag = (str) => {
    if (str) {
        //去掉所有的html标记
        return str.replace(/<[^>]+>/g, "");
    }
}

@action
setDafalutValue = (value) => {
  this.browserValue = value;
}

  @action
  setValue = (params = {}) => {
    //sheet.getCell(row, col).value((valueObj || []).map(d => ({ id: d.id, name: this.delHtmlTag(d.name) })));
    console.log(params,"params");
    if(this.currentCell) {

      switch(this.type) {
        case '164':
        case '4':
        let p1 = params[2] ||{};
        console.log(p1, p1[0].name)
        if(p1[0].name) {
          this.currentCell.value((p1 || []).map(d => ({ id: d.id, name: this.delHtmlTag(d.name) })));
        } else {
          this.currentCell.value((params[3] || []).map(d => ({ id: d.id, name: this.delHtmlTag(d.name) })));
        }
        break;
        default:
            this.currentCell.value((params || []).map(d => ({ id: d.id, name: this.delHtmlTag(d.name) })));
      }

      
    }
    
  }
}